package client;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.Serializable;
import java.net.Socket;

import common.ServerSocket;



public class AspettaRisp extends Thread implements Serializable{
	
	private Client client;
	private BufferedReader buff;
	private String t;
	private int i;
	private boolean chiudiprog;
	
	private static final String to1="@Hai 30 secondi per decidere se confermare o passare il turno";
	private static final String to2="@Hai 2 minuti per decidere la mossa da compiere";
	
	
	public AspettaRisp(Client c, BufferedReader buffr){
		client=c;
		buff=buffr;
		chiudiprog=false;
	}
	
	
	public void setChiudiprog(boolean chiudiprog) {
		this.chiudiprog = chiudiprog;
	}


	public boolean isChiudiprog() {
		return chiudiprog;
	}


	public void run(){
		
		while(!chiudiprog){
						
			try {
				t = new String(buff.readLine());
				char[] mex=t.toCharArray();
				for(i=0;mex[i]!='@';i++);
				
				if(t.substring(i+1, i+3).equals("ca")){
					client.getVisualization().displayOk(t);
				}
				if(t.substring(i+1, i+3).equals("Se")){
					client.getVisualization().display(t);
				}
				else if(t.substring(i+1, i+3).equals("la")){
					client.gameOver(t);
				} 
				else if((t.equals(to1))){
					client.getVisualization().display(t);
				}
				else if((t.equals(to2))){
					client.getVisualization().display(t);
				}
				else if(t.equals("@Tempo Scaduto.Passa il turno")){
					client.getVisualization().display(t);
				}		
				else{
					client.setRisposta(t);
				}
			
			} catch (IOException e) {
				e.printStackTrace();
				System.exit(0);
			}
			
			
		}

	}
}
